package com.app.buss.ui;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.app.buss.R;
import com.app.buss.base.BaseActivity;
import com.app.buss.mvp.presenter.MainPresenter;
import com.app.buss.mvp.view.IMainView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AddTopicActivity extends BaseActivity<MainPresenter> implements IMainView {


    @BindView(R.id.et_topic)
    EditText etTopic;

    @Override
    protected MainPresenter createPresenter() {
        return new MainPresenter(this);
    }

    @Override
    protected int bindContent() {
        return R.layout.aty_add_topic;
    }

    @Override
    protected void initSome() {
        initToolBar("New topic", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(TextUtils.isEmpty(etTopic.getText().toString())){
                    toastShow("Please enter content!");
                }else {
                    SharedPreferences sharedPreferences = getSharedPreferences("topic",MODE_PRIVATE);
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    int size = sharedPreferences.getInt("size",0);
                    size += 1;
                    editor.putString(size+"",etTopic.getText().toString());
                    editor.putInt("size",size);
                    editor.apply();
                    editor.commit();
                    toastShow("Success!");
                    setResult(RESULT_OK);
                    finish();
                }
            }
        },R.drawable.ic_send);
    }

    @Override
    public void getDataSuccess(Object model) {
    }

    @Override
    public void getDataFail(String msg) {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
